package br.ucb.modelo.dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import br.ucb.exceptions.PersistenceException;

public class ConnectionFactory {
    private static Connection con;
    private static String URL = "jdbc:mysql://localhost:3306/bazar";
    private static String USER = "root";
    private static String PASS = "jesus2013";
    
    protected static Connection getConnection() throws PersistenceException{
    	try {
    		Class.forName("com.mysql.jdbc.Driver");
    		con = DriverManager.getConnection(URL, USER, PASS);
    	    return con;
    	} catch (SQLException e) {
    		e.printStackTrace();
    		throw new PersistenceException();
    	} catch (ClassNotFoundException e) {
			e.printStackTrace();
			throw new PersistenceException();
		}
    }
    
    protected static void close() throws PersistenceException{
    	try {
    		if(con != null)
    		con.close();
    	} catch (SQLException e) {
    		e.printStackTrace();
    		throw new PersistenceException();
    	}
    }
}
